trigger CaseTrigger_AT on Case (before insert, before update) {
    CaseTriggerHandler_AC handler = new CaseTriggerHandler_AC();
    if(Trigger.isUpdate){  
        if(Trigger.isBefore){
            handler.OnBeforeUpdate(Trigger.new, Trigger.oldMap);
            // Update Case Type details for action - before update
            //Check if the case details has been changed
            boolean isCaseTypeUpdated = false;
            //Added by Sreekanth SV Vegi for email updation from account or lead
                    //handler.EmailfromleadorAccount(Trigger.new);
            //Ended by Sreekanth SV Vegi
            for(Case newCaseDetails : Trigger.new){
                for(Case oldCaseDetails : Trigger.old){
                /*If the case type details such as category or group or activity is changed
               then case details should be updated accordingly*/        
                    System.debug('Old case:' +oldCaseDetails.Case_Name__c +'New Case'+newCaseDetails.Case_Name__c);
                    if(newCaseDetails.Case_Name__c != oldCaseDetails.Case_Name__c ||
                       newCaseDetails.Group__c != oldCaseDetails.Group__c ||
                       newCaseDetails.Category__c != oldCaseDetails.Category__c ||
                       newCaseDetails.Activity__c != oldCaseDetails.Activity__c){
                    
                        isCaseTypeUpdated = true;
                    }
                }
            }
            //If the case details have been changed update the Case with updated Priority and Case Owner
            if(isCaseTypeUpdated==true){
                
                handler.onUpdateCaseDetails(Trigger.new);
            }
            //Else update the case only when the status is transferred
            else{
                handler.onUpdateCase(Trigger.new);
            }
        }
    }
    if(Trigger.isInsert){
        
        if(Trigger.isBefore){
         //Added by Sreekanth SV Vegi
        //    handler.EmailfromleadorAccount(Trigger.new);
         //Ended by Sreekanth SV Vegi
            handler.onBeforeInsert(Trigger.new);
            // Update Case Type details for action - before insert
            handler.onCreateCase(Trigger.new);
          }
         /* if(Trigger.isAfter){
            handler.onAfterInsert(Trigger.new);
          }*/
    }  
    
    //Ended by Sreekanth SV Vegi
}